let Runtime = require('../runtime/index')
let Modules = require('../modules')
let SessionStore = Runtime.SessionStore

module.exports = {
  '/api/user/logout': {
    method: 'post',
    mock: false,
    callback: function(req, res, callback) {
      var actionResult = {}
      req.session.reload(function() {
        console.log(req.session)
        console.log(req.sessionID)
        let sessionId = SessionStore.getSessionId(req)
        let accessInfo = SessionStore.getAccessInfo(req)
        if (sessionId && accessInfo && accessInfo.accessToken) {
          Modules.sso.logoutAsync(sessionId, accessInfo.accessToken)
            .then((result) => {
              req.session.cookie.maxAge = 0
              actionResult.code = 0
              actionResult.success = true
              actionResult.msg = ''
              callback(actionResult)
            })
        } else {
          req.session.cookie.maxAge = 0
          actionResult.code = 0
          actionResult.success = true
          actionResult.msg = ''
          callback(actionResult)
        }
      })
    }
  },
  '/api/user/test': {
    method: 'get',
    mock: false,
    callback: function(req, res, callback) {
      var actionResult = {}
      console.log(req.session)
      callback({success:true,msg:req.sessionID})
    }
  }
}
